<?php


namespace app\task\controller;

use app\api\model\Order as OrderModel;
use app\api\service\Bank;
use app\api\service\CashServiceJft;
use app\common\exception\BaseException;
use app\common\model\ChannelCcard;
use app\task\model\ChannelBcard;
use think\Log;

class Notifyylys extends \think\Controller
{
    public function bindcards(){

    }
    public function bindccard(){

    }

    /**
     * 交易回调
     */
    public function pay_notifiy(){
        $prama = $this->request->post();
        $res = $prama;
        //更改对应状态
        $status = $res['respCode'] == '0000'?1:0;
        $order_no = $res['orderNo'];
        if ($status){
            // 获取商品结算信息
            $model = new OrderModel;
            try {
                if ($model->payOrder($order_no)){
                    $bank = new Bank();
                    $bank->cash($order_no);
                    return $this->renderJson('0000','执行成功');
                }else{
                    return $this->renderJson('0000','找不到符合条件的订单');
                }
            } catch (\Exception $e) {
                throw new BaseException(['code'=>'0000','msg' => $e->getMessage()]);
            }
        }else{
            $model = OrderModel::getOrderDetailByOrderNo($order_no);
            if ($model->cancels()) {
                return $this->renderJson('0001','订单异常:'.$res['respMsg']);
            }
            return $this->renderJson('0002','订单异常:'.$res['respMsg']);
        }

    }

    /**
     * 提现回调
     */
    public function cash_notifiy(){

    }

    protected function renderJson($code = self::JSON_SUCCESS_STATUS, $msg = '', $data = [])
    {
        header('Access-Control-Allow-Origin: *');
        return compact('code', 'msg', 'data');
    }
}